/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.car.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.car.entity.GpsInfo;
import com.thinkgem.jeesite.modules.car.service.GpsInfoService;

/**
 * 定位信息Controller
 * @author xiaoqian
 * @version 2018-01-06
 */
@Controller
@RequestMapping(value = "${adminPath}/car/gpsInfo")
public class GpsInfoController extends BaseController {

	@Autowired
	private GpsInfoService gpsInfoService;
	
	@ModelAttribute
	public GpsInfo get(@RequestParam(required=false) String id) {
		GpsInfo entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = gpsInfoService.get(id);
		}
		if (entity == null){
			entity = new GpsInfo();
		}
		return entity;
	}
	
	@RequiresPermissions("car:gpsInfo:view")
	@RequestMapping(value = {"list", ""})
	public String list(GpsInfo gpsInfo, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<GpsInfo> page = gpsInfoService.findPage(new Page<GpsInfo>(request, response), gpsInfo); 
		model.addAttribute("page", page);
		return "modules/car/gpsInfoList";
	}

	@RequiresPermissions("car:gpsInfo:view")
	@RequestMapping(value = "form")
	public String form(GpsInfo gpsInfo, Model model) {
		model.addAttribute("gpsInfo", gpsInfo);
		return "modules/car/gpsInfoForm";
	}

	@RequiresPermissions("car:gpsInfo:edit")
	@RequestMapping(value = "save")
	public String save(GpsInfo gpsInfo, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, gpsInfo)){
			return form(gpsInfo, model);
		}
		gpsInfoService.save(gpsInfo);
		addMessage(redirectAttributes, "保存定位信息成功");
		return "redirect:"+Global.getAdminPath()+"/car/gpsInfo/?repage";
	}
	
	@RequiresPermissions("car:gpsInfo:edit")
	@RequestMapping(value = "delete")
	public String delete(GpsInfo gpsInfo, RedirectAttributes redirectAttributes) {
		gpsInfoService.delete(gpsInfo);
		addMessage(redirectAttributes, "删除定位信息成功");
		return "redirect:"+Global.getAdminPath()+"/car/gpsInfo/?repage";
	}

}